<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>天禾人才</title>
	<meta name="format-detection" content="telephone=no">
	<meta name="viewport" content="minimal-ui=yes,width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<meta name="msapplication-tap-highlight" content="no">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">

	<link rel="stylesheet" type="text/css" href="css/public.css">
	<link rel="stylesheet" type="text/css" href="css/registered.css">
	
</head>
<body>
	<div class="header">
		<div class="top">
			<div class="sn-nav-back">
				<a href="javascript:;" onclick="javascript:history.back(-1);"><img src="img/back.png"></a>
			</div>
			<div class="sn-nav-title of">注册</div>
		</div>
	</div>
	<div class="container">
		<!-- <img src="img/login.jpg"> -->
		<div class="content">
			<div class="login">
				<!-- <img src="img/logo.png"> -->
				<ul>
					<li>
						<input id="phone" name="phone" placeholder="用户名/手机号" type="text" value="">
					</li>
					<li class="yzm">
						<input id="imgCode" name="imgCode" placeholder="请填写图形验证码" type="text" value="">
						<h2 style="width: 86px;"><a href="javascript:;"></a><img src="/captcha" onclick="javascript:this.src='/captcha?'+new Date()*1" style="width: 100%;"/></h2>
					</li>
					<li class="yzm">
						<input id="yzm" name="yzm" placeholder="请填写短信验证码" type="text" value="">
						<h2><a href="javascript:;" id="yzm_btn">获取短信验证码</a></h2>
					</li>
					<li>
						<input id="password" name="password" placeholder="设置密码" type="password" value="">
					</li>
					<li style="margin-top: 20px;text-align: center;">
						<span>天禾人才用户交流qq群:</span>
						<a style="color: #0097e7;" href="http://www.baidu.com">123456789</a>
					</li>
					<!-- <li>
						<input id="refferee" name="refferee" placeholder="推荐码（选填）" type="text" value="">
					</li> -->
					<li class="checkbox1">
						<p><input class="checkbox" type="checkbox" checked="" neme="">我已接受并阅读<a href="javascript:;">《阅读并同意此协议》</a></p>
					</li>
					<li>
						<h3><a href="javascript:;" id="submit">立即注册</a></h3>
					</li>
				</ul>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/base.js"></script>
<script type="text/javascript">


$("#submit").click(function(){
    var phone=$("#phone").val();
    var pwd=$("#password").val();
    var code=$("#yzm").val();
    var refferee=$("#refferee").val();
    
    $.ajax({
        type: 'post',
        dataType: 'JSON',
        async:'false',
        url: "/user/register",
        data:{
              pwd:pwd,
              phone:phone,
              code:code,
              refferee:refferee
        },
        success: function(result){
          	if(result.code == 0){
	           localStorage.setItem('user_info',JSON.stringify(result.data));
	           alert('注册成功!');
	           window.location.href='index.html';
          	}else{
           		alert(result.msg);
          	}
        }
    });
})

$("#yzm_btn").click(function(){
	if($(this).hasClass('unclick')){
		return false;
	}
	var reg=/^(((1[0-9][0-9]{1})|159|153)+\d{8})$/;
	var phone= $.trim($("#phone").val());
	if(!reg.test(phone)){
		alert("请输入正确的手机号");
		return false;
	}
	var imgCode = $("#imgCode").val();
	
	$.ajax({
		type: "POST",
		url: "/user/phone/check",
		data: "phone="+phone,
		dataType:"json",
		async:false,
		success: function(data){
			console.log(data);
			if(data.code != 0){
				alert("此手机号已被注册");
				return false;
			}else{
				$.ajax({
					type: "POST",
					url: "/util/sms/send",
					data: {"phone":phone,
						"imgCode":imgCode
					},
					dataType:"json",
					async:false,
					success: function(data){
						$("#yzm_btn").addClass('unclick');
						$("#yzm_btn").html('90秒后重新获取');
						timedCount();
					},error:function(data){
						alert("获取验证码失败");
					}
				});
			}
		}
	});
});

var c=0 ;
function timedCount(){
	$("#yzm_btn").addClass('unclick');
	c++;
	if(c==90){
		$("#yzm_btn").removeClass('active');
		$("#yzm_btn").text("获取验证码");
		$("#yzm_btn").removeClass('unclick');
		c=0;
		return false;
	}else{
		$("#yzm_btn").text((90-c)+"秒后重新获取");
	}
	setTimeout("timedCount()",1000);
};
</script>

</html>